/*************************************************
Author: tony
Date: 10/24/2012
Description:
Notes:
*************************************************/

#ifndef __CShopMgr_h__
#define __CShopMgr_h__

#include "../storage/CUserStorage.h"
#include "CUserShop.h"
#include "CShopConfig.h"

namespace CTLib
{
    class CEnpNetHead;
}

class PBMsgHead;
class CPlayerOnlineData;
class MsgGridItemInfo;
class CShopHistoryItemData;
class MsgAnsShopInfo;
class CClanEntryShop;
#define SHOP_ITEM_SALE_OUT  0xFFFF
class CShopMgr
{
    friend class CClanEntryShop;
public:
    enum SHOP_TYPE
    {
        SHOP_TYPE_MIN = 1,
        SHOP_TYPE_MAX = 2,

        SHOP_TYPE_NEARBY = 1,   //随身商店
        SHOP_TYPE_BUYBACK = 2,  //回购列表
       	SHOP_TYPE_MYSTICAL = 3, //神秘商店
        SHOP_TYPE_EQUIP = 4,    //装备商店
        SHOP_TYPE_CLAN = 5,     //家族商店   
        SHOP_TYPE_CRYSTAL = 6,  //宝石商店
    };

	CShopMgr()
    {
	}

	virtual ~CShopMgr()
    {

	}

	//初始化用户商店
	int  InitData(CUserShop & stUserShop, CShopData & stShopData);
    void GetData(CUserShop & stUserShop, CShopData & stShopData);

    //用户注册时,初始化神秘商店
    int InitMysticalShop (unsigned int uiGid, CUserShop & stUserShop, int iNowTime, CShopData & stShopData);

	//读取配置
	int LoadConfig(const char* szCfgPath);

	//更新神秘商店中物品
	int RefreshShopItem(unsigned int uiGid, CUserShop & stUserShop, short sPlayerLevel, unsigned char ucUpdateType);

    //获取商店信息
	int GetShopItem (short sRoleLevel, unsigned char ucShopType, unsigned short usPos, CUserShop & stUserShop, CShopItemConfig& stConfigData);


    //获取随身商店信息
    int GetNearByShopConfig (short sRoleLevel, unsigned short usPos, CShopItemConfig& stConfigData);

    //发送信息
    void SendInfoToFront (short sRoleLevel,CUserShop & stUserShop, unsigned char ucShopType, PBMsgHead stMsgHead, CEnpNetHead & stEnpHead);

    //获取价格
    int GetBuyPrice(short sRoleLevel, CUserShop& stUserShop, unsigned char ucShopType, unsigned short usPos, unsigned int& uiGoldPrice, unsigned int& uiSilverPrice);

    //添加回购物品
    int AddBuyBackItem(CUserShop & stUserShop, CShopBuyBackItem & stBuyBackItem, CPlayerOnlineData& stPlayerOnlineData);

    //取出回购物品
    int TakeoutBuyBackItem(CUserShop& stUserShop, unsigned short usPos, CShopBuyBackItem& stBuyBackItem);

    //获取回购信息
    int GetBuyBackInfo(CUserShop& stUserShop, unsigned short usPos, CShopBuyBackItem& stBuyBackItem);

    //发送回购物品列表
    void SendBuyBackItemList(CUserShop& stUserShop, PBMsgHead stMsgHead, CTLib::CEnpNetHead stEnpHead);

    //获取商店内容
    int GetShopInfo (short sRoleLevel, CUserShop & stUserShop, unsigned char ucShopType, MsgAnsShopInfo & stAns);

    //获取回购列表
    int GetBuyBackList(CUserShop& stUserShop, MsgAnsShopInfo & stAns);

    //获取宝石商店内容
    int GetCrystalShopList(CUserShop& stUserShop, MsgAnsShopInfo & stAns);

    void UpdateHistory (CShopHistoryItemData & stHistoryItem);

    int DeliverGoods (CPlayerOnlineData & stPlayerOnlineData, CPlayerBaseInfo & stPlayerBaseInfo, CPlayerDetailInfo & stPlayerDetailInfo, 
                      CPlayerDetailInfoEx1 & stPlayerDetailInfoEx1, unsigned int uiGoodsID, int iCount, EN_DELIVER_GOODS_TYPE enType, CDropItem & stDropItem);
        
private:

    CEquipShopConfig _stEquipShopConfig;
    CNearByShopConfig _stNearByShopConfig;
    CMysticalShopConfig _stMystShopConfig;
    CClanShopConfig     _stClanShopConfig;
    CCrystalShopConfig  _stCrystalShopConfig;
    CRoleToShopIdConfig _stRoleToShopId;

    int GetCanCdTime (unsigned int uiGid, int & iCDTime);
};

#endif // __CShopMgr_h__

